using System;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Uportal.Shp.Core.Const;
using Uportal.Shp.Core.Common;
using Uportal.Shp.UI;

namespace Uportal.Shp.UI.Features.FeatureUI
{
    /// <summary>
    /// This class handles events raised during feature activation, deactivation, installation, uninstallation, and upgrade.
    /// </summary>
    /// <remarks>
    /// The GUID attached to this class may be used during packaging and should not be modified.
    /// </remarks>

    [Guid("9fdb49f4-8812-4b77-a885-d97ea93b38a6")]
    public class FeatureUIEventReceiver : SPFeatureReceiver
    {
        // Uncomment the method below to handle the event raised after a feature has been activated.

        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            var web = properties.Feature.Parent as SPWeb;
            if (web == null)
            {
                //_logger.Info("web is null");
                return;
            }
            try
            {
                SPList list = web.Lists[ListInfo.FeedbackToManagmentListName];

                EventReceiverHelper.RegisterEvent(
                   list,
                   typeof(ERFeedBack),
                   SPEventReceiverType.ItemAdded,
                   SPEventReceiverSynchronization.Synchronous,
                   "(Uportal) Item added",10001);

                EventReceiverHelper.RegisterEvent(
                   list,
                   typeof(ERFeedBack),
                   SPEventReceiverType.ItemUpdated,
                   SPEventReceiverSynchronization.Synchronous,
                   "(Uportal) Item updated",10002);

            }
            catch (Exception ex)
            {
                //_logger.Exception(ex);
            }
        }



        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            var web = properties.Feature.Parent as SPWeb;
            if (web == null)
            {
                // _logger.Info("web is null");
                return;
            }

            try
            {
                SPList list = web.Lists[ListInfo.FeedbackToManagmentListName];
                EventReceiverHelper.UnRegisterEvent(list, typeof(ERFeedBack), SPEventReceiverType.ItemAdded);
                EventReceiverHelper.UnRegisterEvent(list, typeof(ERFeedBack), SPEventReceiverType.ItemUpdated);
            }
            catch (Exception ex)
            {
                // _logger.Exception(ex);
            }
        }
    }
}
